def to_int(word):
    nums = {
        "zero": 0,
        "one": 1,
        "two": 2,
        "three": 3,
        "four": 4,
        "five": 5,
        "six": 6,
        "seven": 7,
        "eight": 8,
        "nine": 9,
    }
    return nums[word]

def is_prime(n):
    if n <= 1:
        return False
    for i in range(2, int(n ** 0.5) + 1):
        if n % i == 0:
            return False
    return True

def find_nearest_prime(n):
    i = n + 1
    while not is_prime(i):
        i += 1
    return i

def main():
    words = input().split()
    if len(words) != 3:
        print("Wrong input")
        return

    n = to_int(words[0]) * 100 + to_int(words[1]) * 10 + to_int(words[2])
    print(find_nearest_prime(n))

if __name__ == "__main__":
    main()
